package com.yange.accountbook.ui


import android.graphics.Color
import android.os.Bundle
import android.widget.LinearLayout
import androidx.viewbinding.ViewBinding
import com.gyf.immersionbar.ktx.immersionBar

import com.trello.rxlifecycle2.components.support.RxAppCompatActivity
import com.yange.accountbook.R


/**
 * baseActivity https://xiaozhuanlan.com/topic/4053916287
 */
abstract class BaseActivity<T : ViewBinding> : RxAppCompatActivity() {


    lateinit var binding: T
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = getViewBinding()
        initContent()
        setContentView(binding.root)
        init()
        immersionBar {
            statusBarDarkFont(true, 0.2f)
            fitsSystemWindows(true)
            statusBarColor(R.color.colorMain)
        }

    }

    private fun initContent() {
        window.statusBarColor = Color.TRANSPARENT
        supportActionBar?.hide()
    }

    abstract fun getViewBinding(): T
    private val contentLayout by lazy {         // 创建布局根容器为LinearLayout
        LinearLayout(this).apply {
            orientation = LinearLayout.VERTICAL
        }
    }


    abstract fun init()

    override fun setContentView(layoutResID: Int) {
        layoutInflater.inflate(layoutResID, contentLayout)
    }


}